﻿using System.Collections.ObjectModel;
using LUCAStudios.Silverlight.Controls.Common;

namespace LUCAStudios.Silverlight.Controls
{
    /// <summary>
    /// An observeable collection implementation for LUCA UI container controls
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public sealed class LUCAObservableCollection<T> : ObservableCollection<T> where T : ControlBase
    {
        /// <summary>
        /// Removes the item at the specified index from the collection.
        /// </summary>
        /// <param name="index">The zero-based index of the item to remove.</param>
        protected override void RemoveItem(int index)
        {
            //update control references for the framework
            //during the removal process
            var i = Items[index];
            
            i.PreviousContainerContext = new PreviousContainerContextInfo(i);

            base.RemoveItem(index);

            i.ContainerContext = null;
        }
    }
}
